<template>
	<view class="pageStyle">
		<web-view :src="urls" @error="handleWebViewError"></web-view>
	</view>
</template>
<script>
	import {
		Api
	} from "@/utils/Api.js";
	import {
		mapState
	} from "vuex";
	import {
		getDeptCode
	} from "@/utils/commonHeader.js";

	export default {
		data() {
			return {
				describe: "待办流程",
				url: {
					list: "/m/flow/flowDispose?skey=",
				},
				urls: "",
			};
		},
		onLoad(options) {
			let records = JSON.parse(options.record);
			console.log('options.record', options.record);
			let scanActionType = '',
				scanFlowTypeCode = '',
				scanTargetField = '',
				scanId = '';
			let myActionId = -1;
			if (records) {
				scanActionType = records.scanActionType;
				scanFlowTypeCode = records.scanFlowTypeCode;
				scanTargetField = records.scanTargetField;
				scanId = records.scanId;
				myActionId = records.myActionId;
			}

			this.urls = Api.baseUrl + this.url.list + this.loginInfo.skey + '&myActionId=' + myActionId +
				'&flowTypeCode=' + records.scanFlowTypeCode +
				'&scanActionType=' + scanActionType + '&scanTargetField=' + scanTargetField + '&scanId=' + scanId +
				'&isUniWebview=true';
			console.log('urls', this.urls);
		},
		computed: {
			...mapState(["loginInfo"]),

			// urls() {
			//   let urls = Api.baseUrl + this.url.list + this.loginInfo.skey + '&isUniWebview=true';
			//   return urls;
			// },
		},
		/* onBackPress(options) {
			// 本方法当jump后进入此页面时不生效的原因：因为当前页面栈 必须要大于 2 才生效
			// 自定义返回键事件，返回值为 true 时，表示不执行默认的返回，自行处理此时的业务逻辑
			console.log('onBackPress options', options);
			if (options.from === 'navigateBack') {
				return false;
			}
			// #ifdef H5
			// this为undefined
			// var wv = this.$scope.$getAppWebview();
			let pages = getCurrentPages();
			console.log('pages', pages);
			var page = pages[pages.length - 1];
			var wv = page.$getAppWebview();
			if (wv) {
				wv.canBack(e => {
					// 查询Webview窗口是否可后退 返回true即返回H5上一级
					if (e.canBack) {
						wv.back();
					} else {
						//返回 false 即到 app加载H5的第一页，直接返回app，即H5页面回到app页面中
						uni.navigateTo({
							url: "./pages/applications/applications"
						})
					}
				})
			}
			// 返回true 表示不执行返回键默认操作
			return true;
			// #endif
		}, */
		onShow() {
			console.log('onShow')
			uni.$on('onBackPress', this.onBackPress);
		},
		onHide() {
			uni.$off('onBackPress', this.onBackPress);
		},
		methods: {
			onBackPress(options) {
				console.log('options', options);
				// 来自于导航条返回按钮或者系统返回按钮的事件
				// 在钉钉消息点击跳转到流程处理页面时无效，因为在钉钉中点击返回按钮会回到钉钉消息页面
				if (options.from === 'backbutton') {
					let pages = getCurrentPages();
					console.log('pages', pages);
					// 来自于跳转					
					if (pages[0].route === 'application/jump') {
						console.log('This page is from jump.');
						uni.navigateTo({
							url: "./pages/applications/applications"
						})
						return true; // 返回 true 阻止默认行为，返回 false 继续默认行为
					}
				} else {
					return false;
				}
			},
			handleWebViewError(e) {
			  console.error('WebView 加载失败:', e.detail);
			  uni.showToast({
				title: '页面加载失败，请重试',
				icon: 'none'
			  });
			}
		}
	};
</script>

<style lang="scss" scoped>
</style>